package com.taobaolite.cart_has_items;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface CartRepository extends JpaRepository<CartHasItems, CartPK> {

    @Query("from CartHasItems c where c.cartId.guest.guestId = ?1")
    List<CartHasItems> findByUserId(Long userId);

    @Query("from CartHasItems c where c.cartId.guest.guestId = ?1 and c.cartId.item.itemId = ?2")
    Optional<CartHasItems> findByUserIdAndItemId(Long userId, Long itemId);
}